Microsoft 除了 CLI 的 WMIC 可以得到 WMI 資訊外,
PowerShell 也提供下列 WMI 指令
Get-WmiObject 用來取得 WMI 相關資訊,如無指定 Namespace 預設是 ROOT\CIMV2
簡單列出常用指令
只顯示Name
Get-WmiObject -Class __namespace -Namespace root | select name
List數量很多,分頁查看
Get-WmiObject -List | Out-Host -Paging
列出 WMI Provider
Get-WmiObject -Class __Win32Provider
列出電腦系統資訊
Get-WmiObject -Class Win32_ComputerSystem
Get-WmiObject -Class Win32_ComputerSystem | Select-Object -Property SystemType
Get-WmiObject -Class Win32_ComputerSystem | Select-Object -Property *
列出 CPU 資訊
Get-WmiObject -Class Win32_Processor
列出 BIOS 資訊
Get-WmiObject -Class Win32_BIOS
列出 OS 資訊
Get-WmiObject -Class Win32_Operatingsystem
Get-WmiObject -Class Win32_OperatingSystem | Select-Object -Property *
列出防毒資訊
Get-WmiObject -Namespace root\SecurityCenter2 -Class AntiVirusProduct
列出電腦桌面資訊
Get-WmiObject -Class Win32_Desktop -ComputerName XXXXXXXX-PC
XXXXXXXX-PC 為本機系統關於中的裝置名稱
ComputerName 可以是 computer name, domain name, or IP Address,
Local localhost and 127.0.0.1.
列出 header 為 A到Z的所有資訊
Get-WmiObject -Class Win32_Desktop | Select-Object -Property [a-z]*
列出開頭為 Win 的本機服務
Get-WmiObject -Query "Select * from Win32_Service Where Name Like 'Win%'"
如果應用上述指令寫 Powershell Script 執行時被系統 (Win 11) 阻擋,
需要設定 OS
System -> Privacy & security -> For developers -> PowerShell ->
Turn On "Change execution policy to allow local PowerShell scripts to run without signing. Require signing for remote scripts."
Microsoft Visual Basic Script 也可直接應用 GetObject來執行 WMI 指令
GetObject ("winmgmts:\" & ComputerName & "\ROOT\WMI")